package fluxx.draft;

import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Set;

public class Player {
	
	public static int numInstances;
	private String name;
	
	private Set<Card> hand = new HashSet<Card>();
	private Set<Keeper> keepers = new HashSet<Keeper>();
	
	public Player() {
		this.name = "Player " + (++numInstances);
	}
	
	public String getName() { return name; }
	
	public String toString() { return getName()+": hand = {"+getHand()+"}, keepers = {"+getKeepers()+"}"; }
	
	public CardSet getHand() {
		CardSet returnHand = new CardSet();
		for (Card card : hand) {
			returnHand.add(card);
		}
		return returnHand;
	}
	
	public CardSet getKeepers() {
		CardSet returnHand = new CardSet();
		for (Keeper card : keepers) {
			returnHand.add(card);
		}
		return returnHand;
	}
	
	public void addKeeper(Keeper keeper) {
		keepers.add(keeper);
	}
	
	public void give(Card card) {
		hand.add(card);
	}
	public void take(Card card) throws NoSuchElementException {
		if (!hand.remove(card)) {
			// Remove card. If not exists:
			throw new NoSuchElementException();
		}
	}
}
